<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%String basepath = request.getContextPath(); %>

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" >
	<title>家谱</title>
	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="css/bootstrap-material-design.min.css">
	<link rel="stylesheet" type="text/css" href="css/ripples.min.css">
	<link rel="stylesheet" type="text/css" href="css/css.css">
	<script type="text/javascript">
		var basepath = '<%=basepath%>';
	</script>
	<style type="text/css">
		.STYLE1 {
			color: #0059CC;
			font-weight: bold;
		}
    </style>
</head>
<body>



<!-- navigation left -->
	<div class="row clearfix">
		
		<div class="col-md-12 column">
			<p style="text-align: justify;"><span class="STYLE1">“谱渡”介绍</span><br><br>
			『“谱渡”家谱续修微网站』是上图家谱系统的延续，用户可以通过该网站，
			将个人及家人信息转换成关联数据，存储在百科数据中，实现百科人物数据、上图家谱数据两个异源关联数据的整合，
			同时根据推理规则，实现个人相关家谱推荐及续谱。另外，微网站还实现了基于R语言的分析及可视化。		
			</p>
		</div>
		<div class="col-md-2 column">
		</div>
	</div>
	
<br>
		<div class="row clearfix">
		<div class="col-md-12 column">
		<p style="text-align: center;">系统整体架构图<br><br>
		<img src="<%=basepath%>/overall.png" alt="总体路线图" class="img-rounded">
		</div>
		</div>

	
	

<br><br><br>
<div id="match2jiapu" style="display:none" class="row">
	<table class="table table-striped table-hover">
		<thead>
			<tr>
				<th>所有人物</th>
				<th>涉及家谱</th>
			</tr>
		</thead>
		<tbody id="tbodyPerson">
		            
		</tbody>
	</table>
	<br>
	<div id="sub_result">
	</div>
</div>

<div>



<!--bootstrap-->  
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/material.min.js"></script>
<script type="text/javascript" src="js/ripples.min.js"></script>
<!--d3-->
<script src="js/d3.v3.min.js"></script>

<script src="js/deal.js"></script>
<script>

function next(){
	var a=document.getElementById("nexttest");
	a.style.display="none";
	
	var input=document.getElementById("inputmodel");
	input.style.display="none";
	
	
	var focus=document.getElementById("inputfocusname");
	focus.style.display="block";
	
	var focusButton=document.getElementById("focusPerson");
	focusButton.style.display="block";
	
	var secondStep=document.getElementById("secondStep");
	secondStep.style.display="block";
	
	
	document.getElementById('compl_person').value=people[1];	 
	
	//match到百科
	if(people[1]!=null){
		$.post( 	
				basepath+"/relation/mapBaike",
				{"name": people[1]},
		   	     function(data){
					
		   	    	if(data==null||data==''){
		   	    		document.getElementById('com_desc').value='未被匹配到百度百科';	
		   	    		
		   	    	} else{
		   	    		document.getElementById('mapStatus').innerHTML='已被匹配到百度百科（已补充到描述）!';
		   	    		document.getElementById('com_desc').value=data;
		   	    	}
		   	     }
		); 
	}
}

function last(){
	var a=document.getElementById("nexttest");
	a.style.display="block";
	
	var input=document.getElementById("inputmodel");
	input.style.display="block";
	
	
	var focus=document.getElementById("inputfocusname");
	focus.style.display="none";
	
	var focusButton=document.getElementById("focusPerson");
	focusButton.style.display="none";
	
	var secondStep=document.getElementById("secondStep");
	secondStep.style.display="none";
}


function last2(){
	 window.location.reload();
}

function match(){
	var focus=document.getElementById("inputfocusname");
	focus.style.display="none";
	
	var match2jiapu=document.getElementById("match2jiapu");
	match2jiapu.style.display="block";
	
	var focusButton=document.getElementById("focusPerson");
	focusButton.style.display="none";
	
	var secondStep=document.getElementById("secondStep");
	secondStep.style.display="none";
	
	var submitRes=document.getElementById("submitRes");
	submitRes.style.display="block";
	
	var thirdStep=document.getElementById("thirdStep");
	thirdStep.style.display="block";
	
	var prov=document.getElementById("focus_pro").value;
	var city=document.getElementById("focus_city").value;
	var county=document.getElementById("focus_county").value;
	var persons = document.getElementById("com_ances").value;
	
	$.post( 	
			basepath+"/relation/mapName",
			{"name":people[1],"prov":prov,"city":city,"county":county,"persons":persons},
	   	     function(data){				
					if(data=='0'){
		   	    		$("#tbodyPerson").append("<tr><td>"+$("#nameT").val()+"</td><td><input style='width:90%' type='text' value='没有搜索到推荐的家谱' id='des"+$("#nameT").val()+"'></td></tr>");
		   	    	} else{
		   	    		//alert(data);
		   	    		data = eval("("+data+")");
    					for(var i = 0;i<data.length;i++){
                            var name = data[i].split("--");
    						if(i==0){
    							$("#tbodyPerson").append("<tr><td>"+$("#nameT").val()+"</td><td>" +
                                    "<input type='checkbox' name='selectedwork' value='"+name[0]+"' /> Mapped to: <a target='_blank' href=\"http://jp.library.sh.cn/jp/service/work/list#uri=" + name[0] + "\">" + name[1] + "</a>" +
                                    "</td></tr>");
    						}else{
    							$("#tbodyPerson").append("<tr><td></td><td>" +
                                    "<input type='checkbox' name='selectedwork' value='"+name[0]+"' /> Mapped to: <a target='_blank' href=\"http://jp.library.sh.cn/jp/service/work/list#uri=" + name[0] + "\">" + name[1] + "</a>" +
                                    "</td></tr>");
    						}			
    					}	
		   	    	}
					//other persons
					for(var j=0;j<people.length;j++){
						if(j==1)continue;
						$("#tbodyPerson").append("<tr><td>"+people[j]+"</td><td></td></tr>");
					}
		   	     
			}
	);
}

function submitValues(){
	var childs = $("#tbodyRelation").children();
	var triple = new Array();
	for(var i = 0;i<childs.length;i++){
		var sub = $(childs[i]).children(":eq(1)").html();
		var pro = $(childs[i]).children(":eq(2)").html();
		var obj = $(childs[i]).children(":eq(3)").html();
		
		triple[i] = sub+";;"+pro+";;"+obj;
	}
	
	//related works 被选中的家谱
	var relatedWorks = new Array();
	var obj=document.getElementsByName('selectedwork');
	for(var i=0; i<obj.length; i++){    
		if(obj[i].checked) {
			relatedWorks.push(obj[i].value);
		}
	} 
	
	var childs = $("#tbodyPerson").children();
	var desc = new Array(); 
	for(var i = 0;i<childs.length;i++){
		var sub = $(childs[i]).children(":eq(0)").html();
		var des = $("#des"+sub).val();	//description
		
		if(sub!=null&&sub.trim().length>0) desc.push(sub + ";;" + des);
		//1. sub , desc, literal
		//2. sub, birth, literal (date)
		//3. sub, shl:relatedWork, literal
	}
	$.post( 	
			"<%=basepath%>/relation/addRelation",
	   	     {"triples":triple,"descs":desc,"relatedWorks":relatedWorks},
	   	     function(data){
	   	    	 if(data==null||data==''){
	   	    		document.getElementById('sub_result').innerHTML='maybe failed to update :(';
	   	    	 }else{
	   	    		document.getElementById('sub_result').innerHTML=data;
	   	    	 }
	   	    }
	    );
}
</script>

</body>
</html>